package com.bydq.patrolsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bydq.patrolsystem.entity.PsFunction;
import com.bydq.patrolsystem.entity.PsRolePremission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 写代码是不可能写代码的啦~~
 * @since 2020-05-22
 */
@Mapper
@Repository   //不加这个装配的时候会报红
public interface PsRolePremissionMapper extends BaseMapper<PsRolePremission> {

    //根据角色id查找对应的权限
    @Select("select pf.* from ps_role_premission pp left join ps_function pf " +
            "on pp.functionCode = pf.functionCode where roleId = #{id}")
    public List<PsFunction> selectFunctionListByRoleId(Long id);

    //根据角色id查找对应的权限url
    @Select("select pf.funcUrl from ps_role_premission pp left join ps_function pf " +
            "on pp.functionCode = pf.functionCode where roleId = #{id}")
    public List<String> selectFunctionUrlByRoleId(Long id);


    /**
     * 根据角色id查对应的权限id数组
     * @param id
     * @return
     */
    @Select("select pf.id from ps_role_premission pp left join ps_function pf " +
            "on pp.functionCode = pf.functionCode where roleId = #{id}")
    Long[] selectFunctionIdsByRoleId(Long id);
}
